package com.rykj.ext

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.core.content.ContextCompat
import com.rykj.base.BaseActivity

/**
 * description:
 * <p/>
 * Created by ycw on 2020/09/05.
 */


fun <T : View> BaseActivity.getView(viewId: Int): T? {
    return findViewById<View>(viewId) as? T
}

fun <T : View> BaseActivity.getViewFromLayout(@LayoutRes layout: Int): T? {
    return getViewFromLayout(layout, null, false)
}

fun <T : View> BaseActivity.getViewFromLayout(@LayoutRes layout: Int, root: ViewGroup?, attach: Boolean): T? {
    return LayoutInflater.from(context).inflate(layout, root, attach) as? T
}

fun <T : View> BaseActivity.getViewFromLayout(@LayoutRes layout: Int, @IdRes viewId: Int): T? {
    val v = this.getViewFromLayout(layout) as? View
    return v?.findViewById<View>(viewId) as? T
}

fun BaseActivity.getCompatColor(colorId: Int): Int {
    return ContextCompat.getColor(this, colorId)
}



